package com.seio.edc.util;

import com.nova.frame.dao.datasource.DataSourceManager;
import com.nova.frame.utils.JdbcUtils;
import org.apache.commons.dbutils.ResultSetHandler;

import javax.sql.DataSource;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Map;

/**
 * Created by lenovon on 2016/1/26.
 */
public class DbUtil {
    public static void main(String[] args) {
        try {
//            DataSourceManager.add("collect_db", "collection.properties");
            JdbcUtils.changeDataSource("collect_db");
            Integer value =  JdbcUtils.get("select value from data " +
                    "where gateway_logo = ? " +
                    "and sensor_name = ? " +
                    "and channel_name = ?", new ResultSetHandler<Integer>() {
                @Override
                public Integer handle(ResultSet resultSet) throws SQLException {
                    while (resultSet.next()) {
                        return resultSet.getInt(1);
                    }
                    return null;
                }
            }, "1100201508140307", 1, 177);
            System.out.print(value);
//            DataSource dataSource = DataSourceManager.getDataSource("collect_db");
//            Connection con = dataSource.getConnection();
//            Statement st = con.createStatement();
//            String sql = " select * from data";
//            ResultSet rs = st.executeQuery(sql);
//            while (rs.next()) {
//                System.out.print(rs.getInt(1));
//                System.out.println(rs.getString(2));
//            }
//            rs.close();
//            st.close();
//            con.close();
        } catch (Exception ee) {
            System.out.print(ee.getMessage());
        }
    }
}
